package fx.iog.welcome;

import android.app.ActionBar;
import android.app.Activity;
import android.app.FragmentManager;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import fx.iog.gen.R;

public class LoginActivity extends Activity {
	
	private LoginDialog loginDialog;
	private FragmentManager fragmentDialog;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);

		setContentView(R.layout.activity_welcome);

		this.getActionBar().hide();
		//this.getActionBar().setTitle("Login");

		this.getActionBar().setDisplayShowCustomEnabled(true);
		this.getActionBar().setDisplayShowTitleEnabled(false);

	
		Typeface font = Typeface.createFromAsset(getAssets(),
				"fonts/lucidacaligraph.TTF");
		

		LayoutInflater inflator = LayoutInflater.from(this);
		View v = inflator.inflate(R.layout.text_actionbar, null);

		((TextView) v.findViewById(R.id.title)).setTypeface(font);
		((TextView) v.findViewById(R.id.title)).setText("Login");

		// assign the view to the actionbar
		this.getActionBar().setCustomView(v);

		showDialogLogin();
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.menu_login, menu);
		return super.onCreateOptionsMenu(menu);
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		int id = item.getItemId();
		if(id == R.id.act_logar) {

			loginDialog.show(fragmentDialog, "dialog");
			
			return true;
		} else {
			return false;
		}
	}

	public void showDialogLogin() {
		new Thread(new Runnable() {

			@Override
			public void run() {
				SystemClock.sleep(1600);
				fragmentDialog = getFragmentManager();

				loginDialog = new LoginDialog();
				loginDialog.show(fragmentDialog, "dialog");

				runOnUiThread(new Runnable() {

					@Override
					public void run() {
						ActionBar actionBar = getActionBar();
						actionBar.show();
					}
				});
			}
		}).start();
	}
	

}
